package com.mc.read.pcApi.Aspect;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created  by  fangjian on 2017/8/15
 */

@Component("jcActionSystemLogAspect")
@Aspect
public class McPerAspect {
    private static final Logger LOG = LoggerFactory.getLogger(McPerAspect.class);

    private void controllerAspect() {
    }
//    @AfterReturning(value = "@annotation(mcPer)",returning = "rvt")
//    public void afterReturning(JoinPoint joinPoint, McPer mcPer,Object rvt) {
//
//        try {
//            //类路径
//            String className = joinPoint.getTarget().getClass().getName();
//            //方法名
//            String methodName = joinPoint.getSignature().getName();
//            Object[] args = joinPoint.getArgs();
//            //请求值
//            List<Object> argList = new ArrayList<>();
//            if (null != args && args.length > 0) {
//                for (int i = 0; i < args.length; i++) {
//                    Object arg = args[i];
////                    LOG.info("操作日志：{},{},{}", className, methodName, JsonUtil.toString(arg));
//                    argList.add(arg);
//                }
//            }
//            System.out.println(JSON.toJSONString(joinPoint.getArgs()));
//            System.out.println(JSON.toJSONString(argList.get(0)));
//            BaseRequest baseRequest=
//        } catch (Exception e) {
//            LOG.error("日志记录失败{}", e);
//        }
//
//
//    }

    // 请求method前打印内容
    @Before(value = "@annotation(mcPer)")
    public void methodBefore(JoinPoint joinPoint,McPer mcPer) throws Exception {
        Object[] args = joinPoint.getArgs();
        List<Object> argList = new ArrayList<>();
        if (null != args && args.length > 0) {
            for (int i = 0; i < args.length; i++) {
                Object arg = args[i];
                argList.add(arg);
            }
        }
        System.out.println(mcPer.value());
        System.out.println(JSON.toJSONString(argList.get(0)));
    }

//    @Around(value = "@annotation(mcPer)")
//    public void methodAroud(JoinPoint joinPoint,McPer mcPer) throws Exception {
//        Object[] args = joinPoint.getArgs();
//        List<Object> argList = new ArrayList<>();
//        if (null != args && args.length > 0) {
//            for (int i = 0; i < args.length; i++) {
//                Object arg = args[i];
//                argList.add(arg);
//            }
//        }
//        System.out.println(JSON.toJSONString(argList.get(0)));
//    }


}
